home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / FaceLift / FaceLift Folder / FLWindMisc.c < prev   
Encoding:
C/C++ Source or Header  |  1994-02-22  |  4.4 KB  |  242 lines  |  [TEXT/KAHL]

  1. # include    "TransSkel.h"
  2. # include    "TransDisplay.h"
  3.  
  4. # include    "FLMaca.h"
  5. # include    "FLMapInfo.h"
  6. # include    "FaceLift.h"
  7.  
  8.  
  9.  
  10. static WindowPtr    meterWind = nil;
  11. static WindowPtr    helpWind = nil;
  12. static int            hPara;
  13. static int            errCount;
  14. static Str255        errWindName;
  15.  
  16.  
  17. /* ---------------------------------------------------------------- */
  18. /*                    General Display Window Routines                    */
  19. /* ---------------------------------------------------------------- */
  20.  
  21.  
  22. static pascal void
  23. DWindActivate (Boolean active)
  24. {
  25. WindowPeek    w;
  26.  
  27.     if (!active)    /* deactivated - was it closed? */
  28.     {
  29.         GetPort ((GrafPtr *) &w);
  30.         if (w->visible == 0)
  31.         {
  32.             SkelRmveWind ((WindowPtr) w);    /* yes - remove it */
  33.             if ((WindowPtr) w == helpWind)
  34.                 helpWind = nil;
  35.         }
  36.     }
  37.     FixMenus ();
  38. }
  39.  
  40.  
  41. /*
  42.  * Build a display window.  NewDWindow makes it the current output
  43.  * window for display output.  The window comes up in front unless
  44.  * the meter is present, in which case it comes up under the meter.
  45.  */
  46.  
  47. void
  48. DisplayWindow (StringPtr title, Boolean visible)
  49. {
  50. WindowPtr    w;
  51. Rect                r;
  52. static int            i = 0;
  53. int        h, v;
  54.  
  55.     if (meterWind != nil && i < 1)
  56.         i = 1;
  57.     h = i * 23 + 5;
  58.     v = h + 65;
  59.     SetRect (&r, h, v, h + 350, v + 200);
  60.     SetDWindowNotify (nil, DWindActivate);
  61.     w = NewDWindow (&r, title, visible, (WindowPtr) -1L, true, 0L);
  62.     if (visible)
  63.         MakeFrontWind (w);
  64.     if (++i == 4)
  65.         i = 0;
  66. }
  67.  
  68.  
  69. /* ---------------------------------------------------------------- */
  70. /*                        Meter Window Routines                        */
  71. /* ---------------------------------------------------------------- */
  72.  
  73.  
  74. void
  75. MeterPos (int h, int lineNo)
  76. {
  77.     SetPort (meterWind);
  78.     MoveTo (h, (int) (lineNo * 16 + 14));
  79. }
  80.  
  81.  
  82. void
  83. MeterString (StringPtr s)
  84. {
  85.     SetPort (meterWind);
  86.     DrawString (s);
  87. }
  88.  
  89.  
  90. void
  91. MeterInt (int i)
  92. {
  93. Str255    s;
  94.  
  95.     NumToString ((int) i, s);
  96.     MeterString (s);
  97. }
  98.  
  99.  
  100. void
  101. StartMeterParaInfo (int paras)
  102. {
  103. PenState    p;
  104.  
  105.     MeterPos (5, 1);
  106.     MeterString ("\pTotal Paragraphs:  ");
  107.     MeterInt (paras);
  108.     MeterString ("\p      Current:  ");
  109.     GetPenState (&p);
  110.     hPara = p.pnLoc.h;
  111. }
  112.  
  113.  
  114. void
  115. SetMeterNum (int i)
  116. {
  117.     MeterPos (hPara, 1);
  118.     MeterInt (i);
  119. }
  120.  
  121.  
  122. void
  123. MeterErase (void)
  124. {
  125.     SetPort (meterWind);
  126.     EraseRect (&meterWind->portRect);
  127. }
  128.  
  129.  
  130. static pascal void
  131. MeterClobber (void)
  132. {
  133.     DisposeWindow (meterWind);
  134.     meterWind = nil;
  135. }
  136.  
  137.  
  138. void
  139. MeterBegin (void)
  140. {
  141. Rect    r;
  142.  
  143.     SetRect (&r, 0, 0, 340, 36);
  144.     if (SkelQuery (skelQHasColorQD))
  145.     {
  146.         meterWind = NewCWindow (nil, &r, "\p", false, dBoxProc,
  147.                             (WindowPtr) -1L, false, 0L);
  148.     }
  149.     else
  150.     {
  151.         meterWind = NewWindow (nil, &r, "\p", false, dBoxProc,
  152.                             (WindowPtr) -1L, false, 0L);
  153.     }
  154.     (void) SkelWindow (meterWind, nil, nil, nil, nil, nil, MeterClobber, nil, false);
  155.     ValidRect (&meterWind->portRect);
  156.     TextFont (0);
  157.     TextSize (0);
  158.     TextMode (srcCopy);
  159.     SkelPositionWindow (meterWind, skelPositionOnParentDevice,
  160.                                     FixRatio (1, 2), FixRatio (1, 10));
  161.     MakeFrontWind (meterWind);
  162. }
  163.  
  164.  
  165. void
  166. MeterEnd (void)
  167. {
  168.     SkelRmveWind (meterWind);
  169. }
  170.  
  171.  
  172. /* ---------------------------------------------------------------- */
  173. /*                        Error Window Routines                        */
  174. /* ---------------------------------------------------------------- */
  175.  
  176.  
  177. /*
  178.  * Initialize an error window.  This just clears the error count
  179.  * and sets the name that will be given the window if an error
  180.  * occurs.  The window doesn't actually appear unless the error
  181.  * message routine is called.
  182.  */
  183.  
  184. void
  185. ErrWindInit (StringPtr fName)
  186. {
  187.     errCount = 0;
  188.     CopyString (fName, errWindName);
  189. }
  190.  
  191.  
  192. void
  193. ErrWindMsge (StringPtr thing, int value)
  194. {
  195.  
  196.     if (!showBadFormats)
  197.         return;
  198.  
  199.     if (errCount++ == 0)    /* first error */
  200.     {
  201.         DisplayWindow (errWindName, true);
  202.     }
  203.     DisplayString (thing);
  204.     DisplayShort (value);
  205.     DisplayLn ();
  206. }
  207.  
  208.  
  209. /* ---------------------------------------------------------------- */
  210. /*                        Help Window Routines                        */
  211. /* ---------------------------------------------------------------- */
  212.  
  213.  
  214. /*
  215.  * Create help window, unless it already exists - in which case 
  216.  * simply pull it to the front.
  217.  */
  218.  
  219.  
  220. void
  221. HelpWindow (void)
  222. {
  223. Rect    r;
  224. Handle    h;
  225.  
  226.     if (helpWind == nil)
  227.     {
  228.         SetRect (&r, 40, 50, 450, 280);
  229.         SetDWindowNotify (nil, DWindActivate);
  230.         helpWind = NewDWindow (&r, "\pInformation Window", false, (WindowPtr) -1L, true, 0L);
  231.  
  232.         h = GetResource ('TEXT', helpTextNum);    /* read help text */
  233.         HLock (h);                            /* lock it and write to window */
  234.         DisplayText (*h, GetHandleSize (h));
  235.         HUnlock (h);
  236.         ReleaseResource (h);            /* done with it, so goodbye */
  237.         SetDWindowPos (helpWind, 0);    /* scroll back to top */
  238.         SetDWindow (nil);                /* no more output to this window */
  239.     }
  240.     MakeFrontWind (helpWind);
  241. }
  242.